<?php 
include_once("Model/treeview_model.php");

class TreeView extends MyController
{
    public $model = "";
    
    public function __construct()
    {
        $this->model = new TreeView_Model();
    }
	
	public function createTreeView()
	{
		
	}
    
    public function treeview()
    {
        $html = "";
        $listTinhThanh = $this->model->getAllTinhThanh();
        while($tinhThanh = mysql_fetch_array($listTinhThanh))
        {
            $html .= "<a class='tinhthanh' href='index.php?control=treeview&task=treeview&matinhthanh={$tinhThanh['matinhthanh']}'>{$tinhThanh['tentinhthanh']}</a>";
            if(isset($_GET['matinhthanh']) && ($_GET['matinhthanh'] == $tinhThanh['matinhthanh']))
            {
                $listQuanHuyen = $this->model->getQuanHuyen($_GET['matinhthanh']);
                while($quanHuyen = mysql_fetch_array($listQuanHuyen))
                {                    
                    $html .= "<a class='quanhuyen' href='index.php?control=treeview&task=treeview&matinhthanh={$_GET['matinhthanh']}&maquanhuyen={$quanHuyen['maquanhuyen']}'>{$quanHuyen['tenquanhuyen']}</a>";
                    if(isset($_GET['maquanhuyen']) && ($_GET['maquanhuyen'] == $quanHuyen['maquanhuyen']))
                    {
                        $listPhuongXa = $this->model->getPhuongXa($_GET['maquanhuyen']);
                        while($phuongXa = mysql_fetch_array($listPhuongXa))
                        {                    
                            $html .= "<a class='phuongxa' href='index.php?control=treeview&task=treeview&matinhthanh={$_GET['matinhthanh']}&maquanhuyen={$quanHuyen['maquanhuyen']}&maphuongxa={$phuongXa['maphuongxa']}'>{$phuongXa['tenphuongxa']}</a>";
                            if(isset($_GET['maphuongxa']) && ($_GET['maphuongxa'] == $phuongXa['maphuongxa']))
                            {
                                $listThonXom = $this->model->getThonXom($_GET['maphuongxa']);
                                while($thonXom = mysql_fetch_array($listThonXom))
                                {                    
                                    $html .= "<a class='thonxom' href='index.php?control=treeview&task=treeview&matinhthanh={$_GET['matinhthanh']}&maquanhuyen={$quanHuyen['maquanhuyen']}&maphuongxa={$phuongXa['maphuongxa']}&mathonxom={$thonXom['mathonxom']}'>{$thonXom['tenthonxom']}</a>";
                                }
                            }
                        }
                    }
                }
            }
        }
        include("View/header.php");
        include("View/treeview/treeview.php");
        include("View/footer.php");
    }
}

?>